<!DOCTYPE html>    

<html class="theme-next gemini use-motion" lang="zh-Hans">

<head>
    <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="git," />










<meta name="description" content="什么是GitGit 是目前世界上最牛逼、最先进的分布式版本控制系统而且还是开源的。 什么是版本控制系统？ 首先举个简单的例子，当你在写代码时发现新改写的代码不尽如人意想返回修改之前，那么你可以Ctrl+Z撤销操作回到之前Ctrl+Y回到之后。写一个程序，做一个项目，总不是一蹴而就的，总得修修改改，你有时要保存最新修改的，有时发现写的不好要撤销回到修改之前，Git就担当了这样一个角色，为你的每一次修">
<meta property="og:type" content="article">
<meta property="og:title" content="Git简单入门">
<meta property="og:url" content="https://zym4732.gitee.io/zym4732/2020/01/18/Git%E7%AE%80%E5%8D%95%E5%85%A5%E9%97%A8/index.html">
<meta property="og:site_name" content="JNU-ZYM">
<meta property="og:description" content="什么是GitGit 是目前世界上最牛逼、最先进的分布式版本控制系统而且还是开源的。 什么是版本控制系统？ 首先举个简单的例子，当你在写代码时发现新改写的代码不尽如人意想返回修改之前，那么你可以Ctrl+Z撤销操作回到之前Ctrl+Y回到之后。写一个程序，做一个项目，总不是一蹴而就的，总得修修改改，你有时要保存最新修改的，有时发现写的不好要撤销回到修改之前，Git就担当了这样一个角色，为你的每一次修">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/core_frame.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/test1.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/test2.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/test3.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/test4.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/snap.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/test5.jpg">
<meta property="og:image" content="https://zym4732.gitee.io/images/pictures/Git/test6.jpg">
<meta property="article:published_time" content="2020-01-18T03:23:11.000Z">
<meta property="article:modified_time" content="2020-04-08T15:20:32.218Z">
<meta property="article:author" content="周余民">
<meta property="article:tag" content="git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zym4732.gitee.io/images/pictures/Git/core_frame.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zym4732.gitee.io/zym4732/2020/01/18/Git简单入门/"/>





    <title>Git简单入门 | JNU-ZYM</title>
    









    <!-- <script type="text/javascript">
  //樱花
  var system = {};
  var p = navigator.platform;
  system.win = p.indexOf("Win") == 0;
  system.mac = p.indexOf("Mac") == 0;
  system.Linux = p.indexOf("Linux")==0 && p.indexOf("arm") == -1;
  if (system.win || system.mac || system.Linux) {//如果是电脑
    document.write('<script type="text/javascript" src="/js/sakura.js"><\/script>');
  } 
  </script> -->

    <!-- 网易云插件
  <link rel="stylesheet" href="/musicPlugin/APlayer.min.css">
  <script src="/musicPlugin/APlayer.min.js"></script>
  <div id="aplayer" class="aplayer"  data-id="4915873015" data-server="netease" data-type="playlist" data-fixed="true" data-listfolded="true" data-order="random" data-theme="#F58EA8"></div>
  <script src="/musicPlugin/Meting.min.js"></script> -->

<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

       

    <div class="container sidebar-position-left page-post-detail">
        <div class="headband"></div>

        <a href="https://github.com/zhouyumin" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>
        <style>
            .github-corner:hover .octo-arm {
                animation: octocat-wave 560ms ease-in-out
            }
            
            @keyframes octocat-wave {
                0%,
                100% {
                    transform: rotate(0)
                }
                20%,
                60% {
                    transform: rotate(-25deg)
                }
                40%,
                80% {
                    transform: rotate(10deg)
                }
            }
            
            @media (max-width:500px) {
                .github-corner:hover .octo-arm {
                    animation: none
                }
                .github-corner .octo-arm {
                    animation: octocat-wave 560ms ease-in-out
                }
            }
        </style>

        <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
            <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">JNU-ZYM</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">星河滚烫，你是人间理想</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
        </header>

        <main id="main" class="main">
            <div class="main-inner">
                <div class="content-wrap">
                    <div id="content" class="content">
                        

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zym4732.gitee.io/zym4732/2020/01/18/Git%E7%AE%80%E5%8D%95%E5%85%A5%E9%97%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="周余民">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="JNU-ZYM">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Git简单入门</h1>
        

        <div class="post-meta">

            

          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-01-18T11:23:11+08:00">
                2020-01-18
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/git/" itemprop="url" rel="index">
                    <span itemprop="name">git</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量 <i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.2k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  7
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="什么是Git"><a href="#什么是Git" class="headerlink" title="什么是Git"></a>什么是Git</h2><p>Git 是目前世界上最牛逼、最先进的分布式版本控制系统而且还是开源的。 什么是版本控制系统？ 首先举个简单的例子，当你在写代码时发现新改写的代码不尽如人意想返回修改之前，那么你可以Ctrl+Z撤销操作回到之前Ctrl+Y回到之后。写一个程序，做一个项目，总不是一蹴而就的，总得修修改改，你有时要保存最新修改的，有时发现写的不好要撤销回到修改之前，Git就担当了这样一个角色，为你的每一次修改做好记录，能让你回到过去做出修改的时刻，回到任意你想要去的版本。你可以保留新的，也可以回去把旧的找回来。是不是特别方便，特别随意？ Git不止适用于写代码，对于写论文，写小说等都可用。</p>
<hr>
<a id="more"></a>
<h2 id="安装Git"><a href="#安装Git" class="headerlink" title="安装Git"></a>安装Git</h2><p>去<a href="https://git-scm.com/downloads" target="_blank" rel="noopener">官网</a>下载安装包,如果嫌弃<a href="https://git-scm.com/downloads" target="_blank" rel="noopener">Git官网</a>下载慢的话就去国内镜像站下载，这里推荐<a href="https://npm.taobao.org/mirrors/git-for-windows/" target="_blank" rel="noopener">淘宝镜像站</a>选择需要的版本下载安装，Linux用户则可用以下命令快速安装。</p>
<pre><code class="bash">$ sudo apt install git</code></pre>
<p>安装完第一件事就是让Git认主了 这个操作非常重要，因为每一个 Git 的提交都会使用到这些信息，一旦确定不可更改。 使用以下命令： </p>
<pre><code class="bash">git config --global user.name &quot;用户名&quot; 
git config --global user.email &quot;用户邮箱&quot;</code></pre>
<hr>
<h2 id="理论基础"><a href="#理论基础" class="headerlink" title="理论基础"></a>理论基础</h2><h3 id="Git的核心框架："><a href="#Git的核心框架：" class="headerlink" title="Git的核心框架："></a>Git的核心框架：</h3><p><strong><em>工作区域</em></strong>，<strong><em>暂存区域</em></strong>，<strong><em>Git仓库</em></strong> </p>
<p><img src="/images/pictures/Git/core_frame.jpg" alt="框架"></p>
<p>工作区域（Working Directory）就是你平时存放项目代码的地方</p>
<p>暂存区域（Stage）用于临时存放你的改动，事实上它只是一个文件，保存即将提交的文件列表信息，它有个称号叫索引(index)</p>
<p>Git 仓库（Repository）就是安全存放数据的位置，这里边有你提交的所有版本的数据。其中，HEAD 指向最新放入仓库的版本（HEAD后面会讲）</p>
<h3 id="Git-的工作流程一般是酱紫："><a href="#Git-的工作流程一般是酱紫：" class="headerlink" title="Git 的工作流程一般是酱紫："></a>Git 的工作流程一般是酱紫：</h3><p>在工作目录中添加、修改文件；<br>将需要进行版本管理的文件放入暂存区域；<br>将暂存区域的文件提交到 Git 仓库。因此，Git 管理的文件有三种状态：已修改（modified）、已暂存（staged）和已提交（committed），依次对应上边的每一个流程。</p>
<hr>
<h2 id="开始使用"><a href="#开始使用" class="headerlink" title="开始使用"></a>开始使用</h2><p>教程都在命令行下完成，首先要建立一个大本营（确定你的工作目录），这里我们新建一个叫做 Project 的新文件夹（这里你可以自己找个位置实验，但路径中尽量不要出现中文符号）。 然后将命令行窗口的工作路径切换到刚才创建的 Porject 中，输入命令 <code>git init</code> 即可初始化 Git。 然后你会看到 Project 文件夹中出现一个叫做 .git 的隐藏文件（这个文件夹就是 Git 用来跟踪管理版本迭代的），切记.git文件夹内的内容不要乱动，否则将会有意想不到后果。 </p>
<p>做个简单的演示 先随便建立一个文件吧，然后随便写点内容保存 然后我们要把这个文件提交到暂存区域 使用命令 <code>git add</code>你要提交的文件名 (文件名可以是多个并列 如git add 文件1 文件2，后面的命令同理) 然后把暂存区域的文件提交到仓库 使用命令 <code>git commit -m &quot;提交说明&quot;</code>(PS:提交说明强制要写，不然你以后都不知道这次提交做了些什么事) </p>
<p><img src="/images/pictures/Git/test1.jpg" alt="test1"></p>
<p>记住你未放入过暂存区的文件都处于未跟踪的状态，也就是不归git管，一旦被跟踪git就可以控制它了 如果你把提交过了的文件做了修改，想再提交上去，岂不得再add 然后commit？不必，因为它已经处于跟踪状态了，可一步到位 直接使用 <code>git commit -am &quot;提交说明&quot;</code>就可提交到仓库了 解释： -a 选项其实是专为懒人添加的。添加了 -a 选项，Git 会自动帮你将工作目录中所有“已跟踪”的文件先 add 到暂存区域，然后再执行 commit 命令。另外，-am 是 -a -m 的缩写，多个选项可以写在一起，懒人嘛~</p>
<h2 id="查看状态"><a href="#查看状态" class="headerlink" title="查看状态"></a>查看状态</h2><p>当我们的文件越来越多，怎么区分哪些放入了暂存区，哪些提交了，哪些放入了仓库呢？ 这时使用 <code>git status</code> 命令就可查看当前的状态了</p>
<hr>
<h2 id="查看记录"><a href="#查看记录" class="headerlink" title="查看记录"></a>查看记录</h2><p>使用 <code>git log</code> 命令则可以看到历史提交记录</p>
<p><img src="/images/pictures/Git/test2.jpg" alt="test2"></p>
<hr>
<h2 id="回到过去"><a href="#回到过去" class="headerlink" title="回到过去"></a>回到过去</h2><p>把暂存区的文件拿回到工作区 命令格式： <code>git checkout 文件名</code>如果你把文件提交到了暂存区后又做出了改动（改动可以是修改也可以是删除），使用这条命令把它拿回来的话则做出的修改作废，文件回到了提交到暂存区的那个版本（所以你辛辛苦苦修改的部分会丢失，不小心删掉的会回来，前提是你提交过了）</p>
<p><img src="/images/pictures/Git/test3.jpg" alt="test3"></p>
<hr>
<h2 id="快照回滚"><a href="#快照回滚" class="headerlink" title="快照回滚"></a>快照回滚</h2><p>当我们打算放弃当前的版本，想回到前面的版本的话可以使用reset命令回滚快照 什么是快照？ 想象一下，给一张桌子拍一张照片，纪录了桌子上所有物品的位置、状态，这样就可以称之为快照了。 我们不必存储所有的物品，只需存储这个照片就可以了，下一次想恢复以前的状态的时候，只需要翻出当时的那张照片，再把物品按照那张照片里的位置摆放一下就OK了。 所以快照保存的是每一次提交的版本，你每一次提交到Git仓库则生成一个快照。 回滚快照的命令格式： <code>git reset 快照</code></p>
<p><img src="/images/pictures/Git/test4.jpg" alt="test4"></p>
<p>HEAD表示的是最新保存的快照（类似于头指针吧，会编程的都懂） 使用 <code>git reset HEAD</code>会把HEAD指向的版本（快照）返回到暂存区 当我们想回滚到上上次的快照则可把HEAD 改成HEAD~ HEAD~ 表示 HEAD 的上一个快照，HEAD~~则表示 HEAD 的上上一个快照，如果希望表示HEAD的上n个快照，那么可以直接用 HEAD~n 来表示。</p>
<p>值得注意的是，你回到了哪个快照，HEAD也跟着移动指向了哪个快照，这是同步的，HEAD永远指向当前快照</p>
<p><img src="/images/pictures/Git/snap.jpg" alt="快照"></p>
<p>reset其实是有选项的 <code>git reset HEAD</code>其实是   <code>git reset --mixed HEAD</code>的简写模式，因为mixed是reset的默认选项，所以可以省略</p>
<p><strong>–soft 选项：</strong> soft选项，如其名比较柔软，使用这个选项就只是单纯的移动了HEAD指向的快照版本号，并不会把快照返回到暂存区 例如使用 <code>git reset --soft HEAD~</code>命令，这会使HEAD往前移动指向上一个版本（类似于改变了头指针的指向，有编程基础的很好理解吧）</p>
<p><strong>–hard 选项：</strong> hard选项则相对强硬点了，它不仅会将版本快照返回到暂存区，还会进一步返回到工作区，简直一步到位啊</p>
<p><img src="/images/pictures/Git/test5.jpg" alt="test5"></p>
<p>回滚个别文件 reset 不仅可以回滚指定快照，还可以回滚个别文件。 命令格式为 </p>
<pre><code>git reset 快照 文件</code></pre><p>此命令不会改变 HEAD 的指向（因为你只是回滚快照的部分内容，并不是整个快照，所以 HEAD 的指向不会发生改变），直接将指定快照的指定文件回滚到暂存区域</p>
<p><strong>按照ID回滚快照</strong></p>
<p> 我们可以不通过HEAD直接指定要回滚的快照 命令格式： <code>git reset ID</code>什么是快照的ID？ 你每一次提交的版本都会有一个ID，你可以用git log 看到每次提交的版本的ID（就是前面那串编码了）</p>
<hr>
<h2 id="穿越过去穿越回来"><a href="#穿越过去穿越回来" class="headerlink" title="穿越过去穿越回来"></a>穿越过去穿越回来</h2><p>当我们将快照回滚到了历史版本后悔了想回来怎么办？ 简单只要知道快照的ID就能reset到任意快照 那么怎么查看ID呢？ <code>git reflog</code>命令可以帮到您 Git记录了你的每一次操作，你的一举一动都能通过 <code>git reflog</code>查看，所以不用担心自己会走丢了，看看reflog 就能知道自己干过些什么事了，无论怎么穿越都能找到回去的路。</p>
<p><img src="/images/pictures/Git/test6.jpg" alt="test6"></p>
<blockquote>
<p>参考：<a href="https://fishc.com.cn/forum-334-1.html" target="_blank" rel="noopener">https://fishc.com.cn/forum-334-1.html</a><br>相关视频教程：<a href="https://www.bilibili.com/video/av27780400" target="_blank" rel="noopener">https://www.bilibili.com/video/av27780400</a></p>
</blockquote>
<hr>
<p><strong>其他高阶操作待更新……^_^</strong></p>
<hr>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="周余民 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="周余民 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/git/" rel="tag"><i class="fa fa-tags"></i> git</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/01/17/hexo+Gitee%E5%BB%BA%E7%AB%8Bblog/" rel="next" title="Hexo+Gitee建立blog">
                <i class="fa fa-chevron-left"></i> Hexo+Gitee建立blog
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/01/19/hexo%E4%BD%BF%E7%94%A8Google-prettify%E4%BB%A3%E7%A0%81%E9%85%8D%E8%89%B2%E6%96%B9%E6%A1%88/" rel="prev" title="hexo使用Google-prettify代码配色方案">
                hexo使用Google-prettify代码配色方案 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


                    </div>
                    

 

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80ODMwNy8yNDgwMQ"></div>
    </div>

  



                </div>
                 
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.gif"
                alt="周余民" />
            
              <p class="site-author-name" itemprop="name">周余民</p>
              <p class="site-description motion-element" itemprop="description">计算机蒟蒻</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">61</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">32</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhouyumin" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_43542311" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-CSDN"></i>CSDN</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://blog.jnuwxc.top/" title="学王的blog" target="_blank">学王的blog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://fishc.com.cn/" title="FishC" target="_blank">FishC</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://ilovefishc.com/html5/" title="ilovefishc" target="_blank">ilovefishc</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是Git"><span class="nav-number">1.</span> <span class="nav-text">什么是Git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装Git"><span class="nav-number">2.</span> <span class="nav-text">安装Git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#理论基础"><span class="nav-number">3.</span> <span class="nav-text">理论基础</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Git的核心框架："><span class="nav-number">3.1.</span> <span class="nav-text">Git的核心框架：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-的工作流程一般是酱紫："><span class="nav-number">3.2.</span> <span class="nav-text">Git 的工作流程一般是酱紫：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#开始使用"><span class="nav-number">4.</span> <span class="nav-text">开始使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看状态"><span class="nav-number">5.</span> <span class="nav-text">查看状态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看记录"><span class="nav-number">6.</span> <span class="nav-text">查看记录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#回到过去"><span class="nav-number">7.</span> <span class="nav-text">回到过去</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#快照回滚"><span class="nav-number">8.</span> <span class="nav-text">快照回滚</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#穿越过去穿越回来"><span class="nav-number">9.</span> <span class="nav-text">穿越过去穿越回来</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>

 
            </div>
        </main>

        <footer id="footer" class="footer">
            <div class="footer-inner">
                <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">周余民</span>

  
</div>

<!--
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>
-->



<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script> 
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  
</div>







 
            </div>
        </footer>

         

    </div>

    

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

 


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>

  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>

 
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>

 


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>

 


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  











 

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>




 
 
 
  
 
 
 
 <link rel="stylesheet" href="/lib/prettify/skins/tomorrow-night-eighties.css" type="text/css">
<script src="/lib/prettify/prettify.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function() {
      $('pre').addClass('prettyprint linenums').attr('style', 'overflow:auto;');
      prettyPrint();
  });
</script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/assets/koharu.model.json"},"display":{"position":"right","width":180,"height":360},"mobile":{"show":true},"log":false});</script></body>

</html>